<?php
namespace Procesos\Cargador\Workflow;
class Cargador{

function xmlFromToDbWorflow($fileLocation, $em) {



$workflowDefinitionHandler = new WorkflowDefinitionHandler();



$xml_parser = xml_parser_create('ISO-8859-1');
xml_set_object($xml_parser,$workflowDefinitionHandler);
xml_set_element_handler($xml_parser,"startElement","endElement");
xml_set_character_data_handler($xml_parser,"characters");
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, FALSE);


if (!($fp = fopen($fileLocation, "r"))) {
   throw new Exception('no se puede abrir el archivo '.$fileLocation);
}




while ($file_content = fread($fp, 512)) {
	//echo $file_content.'<hr>';
   if (!xml_parse($xml_parser, $file_content, feof($fp))) {   
   	throw new Exception(sprintf("XML error: %s at line %d",
                   xml_error_string(xml_get_error_code($xml_parser)),
                   xml_get_current_line_number($xml_parser)));
   }
}

xml_parser_free($xml_parser);




$docTypeHandler = $workflowDefinitionHandler->getDocTypeHandler();
print "paso el cargador general \n";


$docTipo = $docTypeHandler->getDocTipo();
print "paso el cargador de docTipo \n";

$salida = $docTipo->getIdentificador();
print $salida; print "\n";

$salida = $docTipo->getDireccionEdicion();
print $salida; print "\n";


$campos = $docTipo->getCampos();

$salida = count($campos);

$salida .= "hay campos \n"; 

print $salida;
$networkHandler = $workflowDefinitionHandler->getNetworkHandler();

print "paso el cargador de de red \n";

$network = $networkHandler->getNetwork();
print "Cargo la red \n";
die();
$em->persist($network);
$lugares = $network->obtenerLugares();
foreach ($lugares as $lugar) {
	$em->persist($lugar);
}
$transiciones = $network->obtenerTransiciones();
foreach ($transiciones as $trans) {
	$em->persist($trans);
}

$arcos = $network->obtenerArcos();

foreach ($arcos as $arc) {
	$em->persist($arc);
}

$em->flush();


die();
$docType->setNetworkRef($network);

$transSetListHandler = $workflowDefinitionHandler->getTransSetListHandler();
$transSetList =$transSetListHandler->getTransSetList();


$placeSetListHandler = $workflowDefinitionHandler->getPlaceSetListHandler();
$placeSetList =$placeSetListHandler->getPlaceSetList();

$network->placeSetList = $placeSetList;

// Creación del vector de incidencia


echo "<br> Red ", $network; 

	$network->initiateNetwork();

echo "<br>comitea la network";

$network->commit();

showPerfInfo();
}
}
?>